<template>
    借款项目名称:
    <input type="text" v-model="info.IIname">
    <select name="" id="" v-model="info.Iid">
        <option value="0">请选择</option>
        <option v-for="i in BindInfo" :value="i.Iid">{{ i.Iyear }}年{{ i.Iinfo }}%</option>
    </select>
    <button @click="PageShow">查询</button>
<table>
    <tr>
        <td>借款项目名称</td>
        <td>最少借款金额</td>
        <td>利率</td>
        <td>操作</td>
    </tr>
    <tr v-for="i in data">
        <td>{{ i.IIname }}</td>
        <td>{{ i.IIminmoney }}</td>
        <td>{{ i.Invest.Iyear }}年{{ i.Invest.Iinfo }}%</td>
        <td><a href="#" @click="Go()">查看明细</a></td>
    </tr>
</table>
<a href="#" @click='PageChange("F")'>首页</a>
<a href="#" @click='PageChange("P")'>上一页</a>
<a href="#" @click='PageChange("N")'>下一页</a>
<a href="#" @click='PageChange("L")'>尾页</a>
当前页码：{{ PageInfo.PageIndex }} 总记录数：{{ PageInfo.ReCount }} 总页数：{{ PageInfo.PageCount }}
一页显示 <input type="text" v-model="Csize"> <button @click="ChangeSize">执行</button>条
前往 <input type="text" v-model="CPageIndex"> <button @click="ChangePageIndex">Go</button>页
</template>
<script setup lang="ts">
import axios from 'axios';
import {ref,onMounted} from 'vue'
const Csize=ref(2)
const CPageIndex=ref(1)
const BindInfo=ref([{
    Iid:0,
    Iinfo:0,
    Iyear:0
}])
onMounted(()=>{
    Bind()
    PageShow()
})
const PageInfo=ref(
    {
        PageIndex:1,
        PageSize:2,
        ReCount:0,
        PageCount:0,
    }
)
const info=ref(
    {
        IIname:'',
        Iid:0
    }
)
const data:any=ref([])
const Bind=()=>{
    axios.get("https://localhost:44355/api/Lx/BindInvest",
        
    ).then(res=>{
        BindInfo.value=res.data
        console.log(BindInfo.value)
    }).catch(err=>{
        console.log(err)
    })
}
const PageShow=()=>{
    axios.get("https://localhost:44355/api/Lx/PageShow",
        {
            params:{
                
                PageIndex:PageInfo.value.PageIndex,
                PageSize:PageInfo.value.PageSize,
                Iid:info.value.Iid,
                IIname:info.value.IIname
            }
        }
    ).then(res=>{
        data.value=res.data.list
        PageInfo.value.PageCount=res.data.PageCount
        PageInfo.value.ReCount=res.data.ReCount
        console.log(data.value)
    }).catch(err=>{
        console.log(err)
    })
}
const Go=()=>{
    location.href="/InvestContext"
}
const PageChange=(m:string)=>{
    if(m=="F"){
        PageInfo.value.PageIndex=1
    }
    if(m=="P")
    {
        if(PageInfo.value.PageIndex>1){

            PageInfo.value.PageIndex--
        }
    }
    if(m=="N")
    {
        if(PageInfo.value.PageIndex<PageInfo.value.PageCount){

PageInfo.value.PageIndex++
}
        
    }
    if(m=="L")
    {
        PageInfo.value.PageIndex=PageInfo.value.PageCount
    }
    PageShow()
}
const ChangeSize=()=>{
    if(Csize.value>PageInfo.value.ReCount){
        alert("数字不合规")
        return
    }
    PageInfo.value.PageSize=Csize.value
    PageShow()
}
const ChangePageIndex=()=>{
    if(CPageIndex.value>PageInfo.value.PageCount||CPageIndex.value<1){
        alert("页码不合规")
        return
    }
    PageInfo.value.PageIndex=CPageIndex.value
    PageShow()
}


</script>